<html>
<head><meta charset="utf-8"><title>Prepresentation of associated constants · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html">Prepresentation of associated constants</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223817171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223817171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223817171">(Jan 24 2021 at 14:46)</a>:</h4>
<p>Constants declared in the impl of a struct use the <code>AssocConstant</code> form, not <code>ConstantItem</code>. That's not particularly useful because the former has an optional default but in impls a definition is required very similar to an actual constant declaration. Also, the definition of an associated type in an impl is a TypedefItem and not an AssocTypeItem as expected.</p>
<p>Compare the output:</p>
<div class="codehilite"><pre><span></span><code>pub trait EasyToImpl {
    /// A type that must be declared.
    type ToDeclare: Clone;
    /// A method you do need to impl.
    fn method_to_impl(&amp;self);
    /// A provided method you do not need to impl.
    fn method_not_to_impl(&amp;self) {}
}

struct Simple;

/// This inherent impl:
impl Simple {
    pub const CONSTANT: usize = 0;
}

/// versus this trait impl
impl EasyToImpl for Simple {
    type ToDeclare = usize;
    fn method_to_impl(&amp;self) {}
}
</code></pre></div>



<a name="223817196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223817196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223817196">(Jan 24 2021 at 14:47)</a>:</h4>
<p><span class="user-mention" data-user-id="229913">@HeroicKatora</span> I love that you're finding all rustdoc inconsistencies <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> are you interested in a PR to fix it?</p>



<a name="223817203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223817203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223817203">(Jan 24 2021 at 14:47)</a>:</h4>
<p>this is a problem with the internal representation too, it duplicates lots of types</p>



<a name="223817358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223817358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223817358">(Jan 24 2021 at 14:51)</a>:</h4>
<p>Not sure if I can make the time besides working on my own toolings, particularly if it affects the internals too (and probably has effects quite spread out over the code base then?)</p>



<a name="223817446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223817446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223817446">(Jan 24 2021 at 14:53)</a>:</h4>
<p>probably yes</p>



<a name="223817449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223817449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223817449">(Jan 24 2021 at 14:53)</a>:</h4>
<p>ok, can you open an issue then?</p>



<a name="223818123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223818123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223818123">(Jan 24 2021 at 15:10)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/81340">https://github.com/rust-lang/rust/issues/81340</a></p>



<a name="223818148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223818148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223818148">(Jan 24 2021 at 15:11)</a>:</h4>
<p>thanks :) btw I think the JSON output would be more helpful than the debug output, it's more concise at least</p>



<a name="223818404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223818404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223818404">(Jan 24 2021 at 15:17)</a>:</h4>
<p>Sure, let's update that.</p>



<a name="223818483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223818483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223818483">(Jan 24 2021 at 15:19)</a>:</h4>
<p>Okay, I need to set <code>no_std</code> and <code>no_core</code> for actually compact output</p>



<a name="223842447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/223842447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#223842447">(Jan 24 2021 at 23:34)</a>:</h4>
<p>Wonder if there would be a use for some way to tell JSON to only output things defined in the current crate, even if just for debugging</p>



<a name="232348130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232348130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232348130">(Mar 29 2021 at 22:54)</a>:</h4>
<p>Working on fixing this now. Leads to an interesting question of whether there should be more info in associated items about what item is their 'parent', it doesn't look like that info is readily available in the JSON currently? Unless I'm missing something not in the paths or items maps</p>



<a name="232349819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232349819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232349819">(Mar 29 2021 at 23:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="319144">CraftSpider</span> <a href="#narrow/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants/near/223842447">said</a>:</p>
<blockquote>
<p>Wonder if there would be a use for some way to tell JSON to only output things defined in the current crate, even if just for debugging</p>
</blockquote>
<p>I think you could do this with a JQ filter</p>



<a name="232350384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232350384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232350384">(Mar 29 2021 at 23:18)</a>:</h4>
<p>hmm it turned out to be kind of tricky, I want to say "any key" but I don't know how to do that</p>



<a name="232353802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232353802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232353802">(Mar 29 2021 at 23:59)</a>:</h4>
<p><code>.index |= [.[] | select(.id | startswith("0:"))] | .paths |= with_entries(select(.key | startswith("0:")))</code> seems to roughly do the correct filtering</p>



<a name="232367454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232367454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232367454">(Mar 30 2021 at 03:17)</a>:</h4>
<p>So, roughly where I stand:<br>
I can swap it over to using constant fairly easily. The issue is then that HTML gets messed up, because it renders the same as a normal constant. This is basically because AssocConstItem/ConstantItem were not designed to actually parallel AssocTypeItem/TypedefItem when implemented.</p>



<a name="232367466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232367466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232367466">(Mar 30 2021 at 03:17)</a>:</h4>
<p>I'm learning a lot diving into the guts of HTML rendering and how rustdoc handles this stuff :P</p>



<a name="232394935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232394935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232394935">(Mar 30 2021 at 09:06)</a>:</h4>
<p>Yeah the hard part of this is getting the html to have the same behavior</p>



<a name="232394981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Prepresentation%20of%20associated%20constants/near/232394981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Prepresentation.20of.20associated.20constants.html#232394981">(Mar 30 2021 at 09:06)</a>:</h4>
<p>I think I remember trying something similar for TypedefItem and it breaking Deref impls or something</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>